from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
import pytest

@pytest.fixture(scope='function')
def driver():
    driver = webdriver.Edge()
    driver.get('https://www.jiuxian.com/')
    driver.maximize_window()
    driver.implicitly_wait(10)

    yield driver
    driver.quit()

def test_jx(driver):
    #点击登录
    driver.find_element(By.XPATH,'/html/body/div[2]/div/div[1]/div/a[1]').click()
    #断言帐号登录
    dy1 = driver.find_element(By.XPATH,'//a[@href="javascript:;"]').text
    print(dy1)
    assert '帐号登录'==dy1
    #输入用户名
    driver.find_element(By.NAME,'uname').send_keys('18615488780')
    #输入密码
    driver.find_element(By.NAME, '_pwd').send_keys('lr123456.')
    #强制等待输入验证码
    sleep(15)
    #点击登录
    driver.find_element(By.ID,'save').click()
    #点击确定
    driver.find_element(By.CSS_SELECTOR,'.bindSub').click()
    sleep(5)
    #断言hi账号
    dy2 = driver.find_element(By.XPATH,'/html/body/div[2]/div/div[1]/div/p').text
    print(dy2)
    #搜索框输入五粮液
    driver.find_element(By.ID,'wd').send_keys('五粮液')
    #回车进行搜索
    driver.find_element(By.ID,'wd').send_keys(Keys.ENTER)
    #断言五粮液酒名
    dy3=driver.find_element(By.XPATH,'/html/body/div[6]/div/div[2]/div[5]/ul/li[1]/div[2]/div[3]/a').text
    print(dy3)
    #点击进入购物车
    driver.find_element(By.XPATH,'//*[@id="addcart_88665"]/a').click()
    #断言加入购物车
    dy4 = driver.find_element(By.XPATH,'/html/body/div[7]/div/div/h6').text
    print(dy4)